<template>
  <div>
    <div v-loading="dataLoading">
      <base-info :base-info="detailData" />
      <!-- <drawing-info :base-info="detailData" /> -->
      <distribute :base-info="detailData" />
      <config-info :base-info="detailData" />
    </div>
    <div style="margin-top:20px" class="qup-title-box"><span class="border" /><span>设计单位确认信息</span></div>

    <el-form
      ref="refForm"
      :rules="formRules"
      :model="formData"
      size="mini"
      style="padding-bottom:50px"
      label-width="150px"
    >

      <el-row>
        <el-col :span="8">
          <el-form-item label="设计单位确认时间:" prop="designUnitConfirmTime">
            <el-input v-model="formData.designUnitConfirmTime" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :rules="[{ required: true, message: '请选择', trigger: 'change' }]" label="确认结果:" prop="confirmResult">
            <el-select
              v-model="formData.confirmResult"
              placeholder="请选择"
              style="width: 100%"
            >
              <el-option label="全部" value="2" />
              <el-option label="部分" value="1" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="16">
          <el-form-item :rules="[{ required: formData.confirmResult==='1', message: '请填写备注', trigger: 'change' }]" label="设计单位确认备注:" prop="designUnitConfirmRemark">
            <el-input v-model="formData.designUnitConfirmRemark" type="textarea" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="footer-btn">
      <el-button style="margin-right:20px" :disabled="submitLoading" size="mini" type="primary" @click="submitForm(1)">提交</el-button>
      <el-button :disabled="submitLoading" size="mini" type="primary" @click="submitForm(0)">保存</el-button>
    </div>
  </div>
</template>
<script>
import BackPageMixin from '@/mixins/backPage'
import { queryDetail, submitDrawingConfirm } from '@/api/autoDesignTask'
import baseInfo from './component/BaseInfo.vue'
import drawingInfo from './component/DrawingInfo.vue'
import distribute from './component/distributeInfo.vue'
import configInfo from './component/ConfigInfo.vue'

export default {
  name: 'DrawingConfirm',
  components: { baseInfo, drawingInfo, distribute, configInfo },
  mixins: [BackPageMixin],
  props: {
  },
  data() {
    return {
      id: '',
      detailData: {},
      designer: [],
      submitLoading: false,
      dataLoading: false,
      formData: {
      },
      formRules: { },
      url: '/pdf-file/'
    }
  },
  watch: {
  },
  async  created() {
    this.id = this.$route.query.id
    if (this.id) {
      this.dataLoading = true
      queryDetail(this.id).then(res => {
        if (res.success) {
          this.detailData = res.data
          const { designUnitConfirmTime, confirmResult, designUnitConfirmRemark, id } = res.data
          this.formData = { designUnitConfirmTime, confirmResult, designUnitConfirmRemark, id }
          this.dataLoading = false
        }
      })
    }
    this.dataLoading = false
  },
  mounted() {
  },
  methods: {

    goBack() {
      this.$store.dispatch('views/goBack')
    },
    submitForm(type) {
      if (this.submitLoading) return
      this.$refs['refForm'].validate((valid) => {
        if (valid) {
          this.submitLoading = true
          submitDrawingConfirm(this.formData, type).then(res => {
            if (res.success) {
              this.submitLoading = false
              this.$message.success('操作成功')
              this.goBack()
            }
          }).catch(() => {
            this.submitLoading = false
          })
        }
      })
    }

  }
}
</script>
<style lang="scss" scoped>
/deep/ .el-breadcrumb__inner{
    color: $qup-color-primary;
  }
</style>
